<template>
  <view class="recycle-container">
    <!-- 自定义导航栏 -->
    <view class="custom-navbar">
      <view class="navbar-content">
        <view class="navbar-left" @click="goBack">
          <text class="back-icon">‹</text>
        </view>
        <view class="navbar-title">回收站</view>
        <view class="navbar-right"></view>
      </view>
    </view>

    <!-- 提示信息 -->
    <view class="tip-banner">
      <text class="tip-text">回收站的绘本会一直保存，不会自动清空</text>
    </view>

    <!-- 回收站列表 -->
    <view class="recycle-list">
      <view 
        class="recycle-item" 
        v-for="(item, index) in recycleItems" 
        :key="index"
      >
        <view class="item-header">
          <text class="series-title">{{ item.seriesTitle }}</text>
          <view class="action-buttons">
            <view class="restore-btn" @click="restoreItem(item, index)">
              <text class="btn-text">还原</text>
            </view>
            <view class="delete-btn" @click="deleteItem(item, index)">
              <text class="btn-text">🗑</text>
            </view>
          </view>
        </view>
        
        <view class="delete-time">
          <text class="time-text">删除时间：{{ item.deleteTime }}</text>
        </view>
        
        <view class="book-info">
          <image class="book-cover" :src="item.coverImage" mode="aspectFit" />
          <view class="book-details">
            <text class="book-title">{{ item.title }}</text>
            <text class="book-subtitle">{{ item.subtitle }}</text>
            <text class="book-age">适合年龄：{{ item.ageRange }}</text>
            <text class="book-level">难度等级：{{ item.level }}</text>
            <text class="book-count">{{ item.bookCount }}本</text>
          </view>
        </view>
      </view>
    </view>

    <!-- 空状态 -->
    <view class="empty-state" v-if="recycleItems.length === 0">
      <text class="empty-text">回收站为空</text>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      recycleItems: [
        {
          seriesTitle: '牛津树系列',
          deleteTime: '2024-06-20 14:30',
          title: '杰克与巨人',
          subtitle: '牛津阅读树经典故事系列',
          ageRange: '3-8岁',
          level: 'Level 5',
          bookCount: '22',
          coverImage: '/static/book-cover-placeholder.svg'
        },
        {
          seriesTitle: '牛津树6级',
          deleteTime: '2024-06-18 09:15',
          title: '牛津阅读树6级系列',
          subtitle: '进阶阅读训练系列',
          ageRange: '5-10岁',
          level: 'Level 6',
          bookCount: '18',
          coverImage: '/static/book-cover-placeholder.svg'
        }
      ]
    }
  },
  
  onLoad() {
    // 从本地存储或API加载回收站数据
    this.loadRecycleData()
  },
  
  methods: {
    // 返回上一页
    goBack() {
      uni.navigateBack()
    },
    
    // 还原项目
    restoreItem(item, index) {
      uni.showModal({
        title: '确认还原',
        content: `确定要还原"${item.seriesTitle}"吗？`,
        success: (res) => {
          if (res.confirm) {
            // 从回收站移除
            this.recycleItems.splice(index, 1)
            
            // 这里可以调用API还原数据
            this.restoreToLibrary(item)
            
            uni.showToast({
              title: '还原成功',
              icon: 'success'
            })
          }
        }
      })
    },
    
    // 永久删除项目
    deleteItem(item, index) {
      uni.showModal({
        title: '确认删除',
        content: `确定要永久删除"${item.seriesTitle}"吗？此操作不可恢复。`,
        success: (res) => {
          if (res.confirm) {
            // 从回收站移除
            this.recycleItems.splice(index, 1)
            
            // 这里可以调用API永久删除数据
            this.permanentDelete(item)
            
            uni.showToast({
              title: '删除成功',
              icon: 'success'
            })
          }
        }
      })
    },
    
    // 加载回收站数据
    loadRecycleData() {
      // 这里可以从API或本地存储加载数据
      // 示例数据已在data中定义
    },
    
    // 还原到书架
    restoreToLibrary(item) {
      // 调用API还原数据到书架
      console.log('还原项目:', item)
    },
    
    // 永久删除
    permanentDelete(item) {
      // 调用API永久删除数据
      console.log('永久删除项目:', item)
    }
  }
}
</script>

<style lang="scss" scoped>
.recycle-container {
  min-height: 100vh;
  background-color: #f5f5f5;
}

/* 自定义导航栏 */
.custom-navbar {
  background-color: #ffffff;
  padding-top: var(--status-bar-height, 44px);
  border-bottom: 1px solid #e5e5e5;
}

.navbar-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 44px;
  padding: 0 16px;
}

.navbar-left {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.back-icon {
  font-size: 24px;
  color: #333333;
  font-weight: bold;
}

.navbar-title {
  font-size: 18px;
  font-weight: 500;
  color: #333333;
}

.navbar-right {
  width: 44px;
}

/* 提示横幅 */
.tip-banner {
  background-color: #fff3cd;
  padding: 12px 20px;
  margin: 16px 20px;
  border-radius: 8px;
  border-left: 4px solid #ffc107;
}

.tip-text {
  font-size: 14px;
  color: #856404;
}

/* 回收站列表 */
.recycle-list {
  padding: 0 20px;
}

.recycle-item {
  background-color: #ffffff;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.series-title {
  font-size: 18px;
  font-weight: 600;
  color: #333333;
}

.action-buttons {
  display: flex;
  gap: 8px;
}

.restore-btn {
  background-color: #28a745;
  padding: 6px 12px;
  border-radius: 6px;
}

.delete-btn {
  background-color: #dc3545;
  padding: 6px 10px;
  border-radius: 6px;
  min-width: 36px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.btn-text {
  color: #ffffff;
  font-size: 12px;
  font-weight: 500;
}

.delete-time {
  margin-bottom: 12px;
}

.time-text {
  font-size: 12px;
  color: #666666;
}

.book-info {
  display: flex;
  gap: 12px;
}

.book-cover {
  width: 80px;
  height: 100px;
  border-radius: 8px;
  background-color: #f0f0f0;
  flex-shrink: 0;
}

.book-details {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.book-title {
  font-size: 16px;
  font-weight: 600;
  color: #333333;
  line-height: 1.4;
}

.book-subtitle {
  font-size: 14px;
  color: #666666;
  line-height: 1.3;
}

.book-age,
.book-level {
  font-size: 12px;
  color: #888888;
}

.book-count {
  font-size: 14px;
  color: #007bff;
  font-weight: 500;
  margin-top: 4px;
}

/* 空状态 */
.empty-state {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 200px;
}

.empty-text {
  font-size: 16px;
  color: #999999;
}
</style>